package com.nulldev.util.threading.legacy.dbg;

public abstract class AbstractInfoStats implements InfoStats
{
    static int defaultHistoryLength;
    protected int nrOfValidValues;
    protected int percentage;
    protected int[] usageHistory;
    protected long lastCpuUsage;
    protected int historyIndex;
    protected int historyLength;

    public AbstractInfoStats() {
        this.historyLength = AbstractInfoStats.defaultHistoryLength;
        this.usageHistory = new int[this.historyLength];
    }

    public int getPercentage() {
        return this.percentage;
    }

    public long getCpuUsage() {
        return this.lastCpuUsage;
    }

    public int getAverageUsage() {
        if (this.nrOfValidValues > 0) {
            int percentage = this.percentage;
            final int[] usageHistory = this.usageHistory;
            for (int length = usageHistory.length, i = 0; i < length; ++i) {
                percentage += usageHistory[i];
            }
            return percentage / this.nrOfValidValues;
        }
        return 0;
    }

    public int[] getHistory() {
        final int[] array = new int[this.historyLength];
        for (int i = 0; i < this.historyLength; ++i) {
            array[i] = this.usageHistory[(this.historyIndex + i) % this.historyLength];
        }
        return array;
    }

    public boolean getSelect() {
        return false;
    }

    public Thread.State getState() {
        return null;
    }

    public void setIndex(final int n) {
    }

    public void setSelect(final boolean b) {
    }

    static {
        AbstractInfoStats.defaultHistoryLength = 10;
    }
}

